package com.code.train.controller;

import com.code.train.context.LoginMemberContext;
import com.code.train.req.PassengerQueryReq;
import com.code.train.req.PassengerSaveReq;
import com.code.train.resp.CommonResp;
import com.code.train.resp.PageResp;
import com.code.train.resp.PassengerQueryResp;
import com.code.train.service.PassengerService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * PassengerController
 *
 * @param
 * @author 南汉卿
 * @return
 * @date 2025/8/15 11:35
 */
@RestController
@RequestMapping("/passenger")
public class PassengerController {

    @Autowired
    PassengerService passengerService;

    @PostMapping("/save")
    public CommonResp<Object> register(@Valid @RequestBody PassengerSaveReq req){
        passengerService.save(req);
        return CommonResp.success();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<PassengerQueryResp>> queryList(@Valid PassengerQueryReq req) {
        req.setMemberId(LoginMemberContext.getId());
        PageResp<PassengerQueryResp> list = passengerService.queryList(req);
        return CommonResp.success(list);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable("id") Long id){
        passengerService.delete(id);
        return CommonResp.success();
    }

    @GetMapping("/query-mine")
    public CommonResp<List<PassengerQueryResp>> queryMine() {
        List<PassengerQueryResp> list = passengerService.queryMine();
        return CommonResp.success(list);
    }
}
